home *** CD-ROM | disk | FTP | other *** search
- package com.ibm.xml.internal;
-
- import com.ibm.xml.framework.ChunkyByteArray;
- import com.ibm.xml.framework.ChunkyCharArray;
- import com.ibm.xml.framework.ParserState;
- import com.ibm.xml.framework.ScanContentState;
- import com.ibm.xml.framework.StringPool;
- import com.ibm.xml.framework.StringProducer;
- import com.ibm.xml.framework.XMLDocumentHandler;
- import com.ibm.xml.framework.XMLErrorHandler;
- import com.ibm.xml.framework.XMLReader;
- import java.io.IOException;
-
- final class UCSReader extends XMLReader implements StringProducer {
- private static final boolean DEBUG_UTF16_BIG = false;
- static final int E_UCS4B = 0;
- static final int E_UCS4L = 1;
- static final int E_UCS2B = 2;
- static final int E_UCS2L = 3;
- static final int E_UCS2B_NOBOM = 4;
- static final int E_UCS2L_NOBOM = 5;
- private ChunkyByteArray fData;
- private int fEncoding = -1;
- private StringPool fStringPool;
- private XMLDocumentHandler fDocumentHandler;
- private XMLErrorHandler fErrorHandler;
- private int fBytesPerChar = -1;
- private boolean fBigEndian = true;
- private ChunkyCharArray fStringCharArray;
- private static char[] fCharacters = new char[256];
- private int fCharDataLength;
-
- UCSReader(ParserState var1, String var2, String var3, ChunkyByteArray var4, int var5) throws IOException {
- super(var1, var2, var3);
- super.fCurrentOffset = var5 != 2 && var5 != 3 ? 0 : 2;
- this.fData = var4;
- this.fEncoding = var5;
- this.fStringPool = var1.cacheStringPool();
- this.fDocumentHandler = var1.getDocumentHandler();
- this.fErrorHandler = var1.getErrorHandler();
- this.fBytesPerChar = this.fEncoding != 0 && this.fEncoding != 1 ? 2 : 4;
- this.fBigEndian = this.fEncoding == 0 || this.fEncoding == 2 || this.fEncoding == 4;
- }
-
- private int getChar(int var1) {
- int var2 = this.fData.byteAt(var1++) & 255;
- if (var2 == 255 && this.fData.atEOF(var1)) {
- return -1;
- } else {
- int var3 = this.fData.byteAt(var1++) & 255;
- if (this.fBytesPerChar == 4) {
- int var4 = this.fData.byteAt(var1++) & 255;
- int var5 = this.fData.byteAt(var1++) & 255;
- return this.fBigEndian ? (var2 << 24) + (var3 << 16) + (var4 << 8) + var5 : (var5 << 24) + (var4 << 16) + (var3 << 8) + var2;
- } else {
- return this.fBigEndian ? (var2 << 8) + var3 : (var3 << 8) + var2;
- }
- }
- }
-
- public int addString(int var1, int var2) {
- return var2 == 0 ? 0 : this.fStringPool.addString(this, var1, var2);
- }
-
- public int addSymbol(int var1, int var2) {
- return var2 == 0 ? 0 : this.fStringPool.addSymbol(this, var1, var2, this.getHashcode(var1, var2));
- }
-
- public void append(ChunkyCharArray var1, int var2, int var3) {
- for(int var4 = var2 + var3; var2 < var4; var2 += this.fBytesPerChar) {
- int var5 = this.getChar(var2);
- var1.append((char)var5);
- }
-
- }
-
- public String toString(int var1, int var2) {
- if (this.fStringCharArray == null) {
- this.fStringCharArray = new ChunkyCharArray(this.fStringPool);
- }
-
- int var3 = this.fStringCharArray.length();
- this.append(this.fStringCharArray, var1, var2);
- int var4 = this.fStringCharArray.length() - var3;
- int var5 = this.fStringCharArray.addString(var3, var4);
- return this.fStringPool.toString(var5);
- }
-
- private int getHashcode(int var1, int var2) {
- int var3 = var1 + var2;
- int var4 = 0;
-
- for(int var5 = 0; var1 < var3; var1 += this.fBytesPerChar) {
- int var6 = this.getChar(var1);
- var4 = StringHasher.hashChar(var4, var5++, var6);
- }
-
- return StringHasher.finishHash(var4);
- }
-
- public boolean equalsString(int var1, int var2, String var3, int var4) {
- int var5 = var1 + var2;
- int var6 = var4;
-
- for(int var7 = 0; var1 < var5; var1 += this.fBytesPerChar) {
- if (var6-- == 0) {
- return false;
- }
-
- int var8 = this.getChar(var1);
- if (var8 != var3.charAt(var7++)) {
- return false;
- }
- }
-
- if (var6 != 0) {
- return false;
- } else {
- return true;
- }
- }
-
- private void appendCharData(int var1) {
- if (fCharacters.length == this.fCharDataLength) {
- char[] var2 = new char[fCharacters.length * 2];
- System.arraycopy(fCharacters, 0, var2, 0, fCharacters.length);
- fCharacters = var2;
- }
-
- fCharacters[this.fCharDataLength++] = (char)var1;
- }
-
- public void callWSCharDataHandler(int var1, int var2, boolean var3) throws Exception {
- for(int var4 = var1 + var2; var1 < var4; var1 += this.fBytesPerChar) {
- int var5 = this.getChar(var1);
- this.appendCharData(var5);
- }
-
- if (this.fDocumentHandler.sendCharDataAsCharArray()) {
- this.fDocumentHandler.ignorableWhitespace(fCharacters, 0, this.fCharDataLength, var3);
- } else {
- int var6 = this.fStringPool.addString(new String(fCharacters, 0, this.fCharDataLength));
- this.fDocumentHandler.ignorableWhitespace(var6, var3);
- }
-
- this.fCharDataLength = 0;
- }
-
- public void callCharDataHandler(int var1, int var2, boolean var3) throws Exception {
- for(int var4 = var1 + var2; var1 < var4; var1 += this.fBytesPerChar) {
- int var5 = this.getChar(var1);
- this.appendCharData(var5);
- }
-
- if (this.fDocumentHandler.sendCharDataAsCharArray()) {
- this.fDocumentHandler.characters(fCharacters, 0, this.fCharDataLength, var3);
- } else {
- int var6 = this.fStringPool.addString(new String(fCharacters, 0, this.fCharDataLength));
- this.fDocumentHandler.characters(var6, var3);
- }
-
- this.fCharDataLength = 0;
- }
-
- public int skipOneChar() throws IOException {
- super.fCurrentOffset += this.fBytesPerChar;
- return super.fCurrentOffset;
- }
-
- public int skipAsciiChar() throws IOException {
- super.fCurrentOffset += this.fBytesPerChar;
- return super.fCurrentOffset;
- }
-
- public int skipToChar(char var1) throws IOException {
- while(true) {
- int var2 = this.getChar(super.fCurrentOffset);
- if (var2 == var1) {
- return super.fCurrentOffset;
- }
-
- super.fCurrentOffset += this.fBytesPerChar;
- }
- }
-
- public int skipPastChar(char var1) throws IOException {
- int var2;
- do {
- var2 = this.getChar(super.fCurrentOffset);
- super.fCurrentOffset += this.fBytesPerChar;
- } while(var2 != var1);
-
- return super.fCurrentOffset;
- }
-
- public boolean skippedValidChar() throws IOException {
- int var1 = this.getChar(super.fCurrentOffset);
- super.fCurrentOffset += this.fBytesPerChar;
- if (var1 < 32) {
- if (var1 == 9) {
- ++super.fCharacterCounter;
- return true;
- } else if (var1 == 10) {
- ++super.fLinefeedCounter;
- super.fCharacterCounter = 1;
- return true;
- } else if (var1 == 13) {
- ++super.fCarriageReturnCounter;
- super.fCharacterCounter = 1;
- return true;
- } else {
- --super.fCurrentOffset;
- if (var1 == -1) {
- this.fData.checkEOF(super.fCurrentOffset + 1);
- }
-
- return false;
- }
- } else {
- ++super.fCharacterCounter;
- if (var1 <= 55295) {
- return true;
- } else if (var1 <= 57343) {
- ++super.fCurrentOffset;
- return true;
- } else if (var1 <= 65533) {
- return true;
- } else {
- --super.fCharacterCounter;
- super.fCurrentOffset -= this.fBytesPerChar;
- return false;
- }
- }
- }
-
- public boolean lookingAtValidChar() throws IOException {
- int var1 = this.getChar(super.fCurrentOffset);
- if (var1 < 32) {
- if (var1 == -1) {
- this.fData.checkEOF(super.fCurrentOffset + 1);
- }
-
- return var1 == 9 || var1 == 10 || var1 == 13;
- } else {
- return var1 <= 55295 || var1 >= 57344 && (var1 <= 65533 || var1 >= 65536 && var1 <= 1114111);
- }
- }
-
- public int skipInvalidChar(int var1) throws Exception {
- int var2 = this.getChar(super.fCurrentOffset);
- super.fCurrentOffset += this.fBytesPerChar;
- switch (var1) {
- case 43:
- String var6 = (new Character((char)var2)).toString();
- String var4 = Integer.toHexString(var2);
- this.fErrorHandler.error2(var1, this.fStringPool.addString(var6), this.fStringPool.addString(var4));
- break;
- case 63:
- case 85:
- String var5 = Integer.toHexString(var2);
- this.fErrorHandler.error1(var1, this.fStringPool.addString(var5));
- break;
- case 80:
- case 82:
- case 110:
- String var3 = (new Character((char)var2)).toString();
- this.fErrorHandler.error1(var1, this.fStringPool.addString(var3));
- }
-
- return super.fCurrentOffset;
- }
-
- public boolean skippedChar(char var1) throws IOException {
- int var2 = this.getChar(super.fCurrentOffset);
- if (var2 == var1) {
- super.fCurrentOffset += this.fBytesPerChar;
- return true;
- } else {
- return false;
- }
- }
-
- public boolean lookingAtChar(char var1) throws IOException {
- return var1 == this.getChar(super.fCurrentOffset);
- }
-
- public boolean skippedSpace() throws IOException {
- int var1 = this.getChar(super.fCurrentOffset);
- if (var1 != 32 && var1 != 9 && var1 != 10 && var1 != 13) {
- return false;
- } else {
- super.fCurrentOffset += this.fBytesPerChar;
- return true;
- }
- }
-
- public boolean lookingAtSpace() throws IOException {
- int var1 = this.getChar(super.fCurrentOffset);
- return var1 == 32 || var1 == 9 || var1 == 10 || var1 == 13;
- }
-
- public int skipPastSpaces() throws IOException {
- while(true) {
- int var1 = this.getChar(super.fCurrentOffset);
- if (var1 != 32 && var1 != 9 && var1 != 10 && var1 != 13) {
- return super.fCurrentOffset;
- }
-
- super.fCurrentOffset += this.fBytesPerChar;
- }
- }
-
- public int skipDecimalDigit() throws IOException {
- int var1 = this.getChar(super.fCurrentOffset);
- if (var1 >= 48 && var1 <= 57) {
- super.fCurrentOffset += this.fBytesPerChar;
- ++super.fCharacterCounter;
- return var1 - 48;
- } else {
- return -1;
- }
- }
-
- public int skipHexDigit() throws IOException {
- int var1 = this.getChar(super.fCurrentOffset);
- if (var1 <= 102 && XMLReader.fgAsciiXDigitChar[var1] != 0) {
- super.fCurrentOffset += this.fBytesPerChar;
- ++super.fCharacterCounter;
- return var1 - (var1 < 65 ? 48 : (var1 < 97 ? 65 : 97) - 10);
- } else {
- return -1;
- }
- }
-
- public boolean skippedAlpha() throws IOException {
- int var1 = this.getChar(super.fCurrentOffset);
- if (var1 <= 122 && XMLReader.fgAsciiAlphaChar[var1] == 1) {
- super.fCurrentOffset += this.fBytesPerChar;
- ++super.fCharacterCounter;
- return true;
- } else {
- return false;
- }
- }
-
- private boolean skippedCharWithFlag(byte var1) {
- int var2 = this.getChar(super.fCurrentOffset);
- if (var2 < 128 && (XMLReader.fgCharFlags[var2] & var1) != 0) {
- super.fCurrentOffset += this.fBytesPerChar;
- ++super.fCharacterCounter;
- return true;
- } else {
- return false;
- }
- }
-
- public final boolean skippedVersionNum() {
- return this.skippedCharWithFlag((byte)1);
- }
-
- public final boolean skippedEncName() {
- return this.skippedCharWithFlag((byte)2);
- }
-
- public final boolean skippedPubidChar() {
- int var1 = this.getChar(super.fCurrentOffset);
- if (var1 < 128) {
- if ((XMLReader.fgCharFlags[var1] & 4) != 0) {
- super.fCurrentOffset += this.fBytesPerChar;
- ++super.fCharacterCounter;
- return true;
- }
-
- if (var1 == 10) {
- super.fCurrentOffset += this.fBytesPerChar;
- ++super.fLinefeedCounter;
- super.fCharacterCounter = 1;
- return true;
- }
-
- if (var1 == 13) {
- super.fCurrentOffset += this.fBytesPerChar;
- ++super.fCarriageReturnCounter;
- super.fCharacterCounter = 1;
- return true;
- }
- }
-
- return false;
- }
-
- public boolean skippedString(char[] var1) throws IOException {
- int var2 = super.fCurrentOffset;
-
- for(int var3 = 0; var3 < var1.length; ++var3) {
- if (this.getChar(var2) != var1[var3]) {
- return false;
- }
-
- var2 += this.fBytesPerChar;
- }
-
- super.fCurrentOffset = var2;
- super.fCharacterCounter += var1.length;
- return true;
- }
-
- public int scanName(char var1, int var2) throws IOException {
- int var3 = super.fCurrentOffset;
- int var4 = this.skipPastName(var1) - var3;
- if (var4 == 0) {
- return -1;
- } else {
- int var5 = var4 == 0 ? 0 : this.fStringPool.addSymbol(this, var3, var4, this.getHashcode(var3, var4));
- return var2 != -1 && var2 != var5 ? -1 : var5;
- }
- }
-
- public int skipPastName(char var1) throws IOException {
- int var2 = this.getChar(super.fCurrentOffset);
- if ((XMLReader.fgCharFlags[var2] & 16) == 0) {
- return super.fCurrentOffset;
- } else {
- do {
- super.fCurrentOffset += this.fBytesPerChar;
- ++super.fCharacterCounter;
- var2 = this.getChar(super.fCurrentOffset);
- if (var1 == var2) {
- return super.fCurrentOffset;
- }
- } while((XMLReader.fgCharFlags[var2] & 32) != 0);
-
- return super.fCurrentOffset;
- }
- }
-
- public int skipPastNmtoken(char var1) throws IOException {
- for(int var2 = this.getChar(super.fCurrentOffset); var1 != var2; var2 = this.getChar(super.fCurrentOffset)) {
- if ((XMLReader.fgCharFlags[var2] & 32) == 0) {
- return super.fCurrentOffset;
- }
-
- super.fCurrentOffset += this.fBytesPerChar;
- ++super.fCharacterCounter;
- }
-
- return super.fCurrentOffset;
- }
-
- public int scanContent(ScanContentState var1) throws Exception {
- int var2 = super.fCurrentOffset;
- int var3 = this.getChar(super.fCurrentOffset);
- super.fCurrentOffset += this.fBytesPerChar;
- if (var3 < 128) {
- if (var3 == -1) {
- super.fCurrentOffset -= this.fBytesPerChar;
- return 4;
- }
-
- byte var4 = XMLReader.fgCharFlags[var3];
- if ((var4 & 8) == 0 && var3 != 10 && var3 != 13) {
- if (var3 == 60) {
- ++super.fCharacterCounter;
- return 1;
- }
-
- if (var3 == 38) {
- ++super.fCharacterCounter;
- return 2;
- }
-
- if (var3 != 93) {
- super.fCurrentOffset -= this.fBytesPerChar;
- return 4;
- }
-
- if (this.getChar(super.fCurrentOffset) == 93 && this.getChar(super.fCurrentOffset + this.fBytesPerChar) == 62) {
- super.fCharacterCounter += 3;
- super.fCurrentOffset += 2 * this.fBytesPerChar;
- return 3;
- }
- } else if (var3 == 32 || var3 == 9 || var3 == 10 || var3 == 13) {
- do {
- if (var3 == 10) {
- ++super.fLinefeedCounter;
- super.fCharacterCounter = 1;
- } else if (var3 == 13) {
- ++super.fCarriageReturnCounter;
- super.fCharacterCounter = 1;
- } else {
- ++super.fCharacterCounter;
- }
-
- var3 = this.getChar(super.fCurrentOffset);
- super.fCurrentOffset += this.fBytesPerChar;
- } while(var3 == 32 || var3 == 9 || var3 == 10 || var3 == 13);
-
- if (var3 < 128) {
- if (var3 == -1) {
- super.fCurrentOffset -= this.fBytesPerChar;
- if (this.fDocumentHandler != null) {
- this.callWSCharDataHandler(var2, super.fCurrentOffset - var2, var1.inCDSect);
- }
-
- return 28;
- }
-
- var4 = XMLReader.fgCharFlags[var3];
- if ((var4 & 8) == 0) {
- if (var3 == 60) {
- ++super.fCharacterCounter;
- if (this.fDocumentHandler != null) {
- this.callWSCharDataHandler(var2, super.fCurrentOffset - this.fBytesPerChar - var2, var1.inCDSect);
- }
-
- return 25;
- }
-
- if (var3 == 38) {
- ++super.fCharacterCounter;
- if (this.fDocumentHandler != null) {
- this.callWSCharDataHandler(var2, super.fCurrentOffset - this.fBytesPerChar - var2, var1.inCDSect);
- }
-
- return 26;
- }
-
- if (var3 != 93) {
- super.fCurrentOffset -= this.fBytesPerChar;
- if (this.fDocumentHandler != null) {
- this.callWSCharDataHandler(var2, super.fCurrentOffset - var2, var1.inCDSect);
- }
-
- return 28;
- }
-
- if (this.getChar(super.fCurrentOffset) == 93 && this.getChar(super.fCurrentOffset + this.fBytesPerChar) == 62) {
- if (this.fDocumentHandler != null) {
- this.callWSCharDataHandler(var2, super.fCurrentOffset - this.fBytesPerChar - var2, var1.inCDSect);
- }
-
- super.fCharacterCounter += 3;
- super.fCurrentOffset += 2 * this.fBytesPerChar;
- return 27;
- }
- }
- } else if (var3 >= 55296 && var3 <= 57343) {
- super.fCurrentOffset += this.fBytesPerChar;
- } else if (var3 == 65534 || var3 == 65535) {
- super.fCurrentOffset -= this.fBytesPerChar;
- if (this.fDocumentHandler != null) {
- this.callWSCharDataHandler(var2, super.fCurrentOffset - var2, var1.inCDSect);
- }
-
- return 28;
- }
- }
- } else if (var3 >= 55296 && var3 <= 57343) {
- super.fCurrentOffset += this.fBytesPerChar;
- } else if (var3 == 65534 || var3 == 65535) {
- super.fCurrentOffset -= this.fBytesPerChar;
- return 4;
- }
-
- ++super.fCharacterCounter;
-
- while(true) {
- var3 = this.getChar(super.fCurrentOffset);
- super.fCurrentOffset += this.fBytesPerChar;
- if (var3 >= 128 || var3 < 0) {
- break;
- }
-
- byte var7 = XMLReader.fgCharFlags[var3];
- if ((var7 & 8) == 0) {
- if (var3 == 10) {
- ++super.fLinefeedCounter;
- super.fCharacterCounter = 1;
- } else {
- if (var3 != 13) {
- break;
- }
-
- ++super.fCarriageReturnCounter;
- super.fCharacterCounter = 1;
- }
- } else {
- ++super.fCharacterCounter;
- }
- }
-
- while(true) {
- if (var3 < 128) {
- if (var3 == -1) {
- super.fCurrentOffset -= this.fBytesPerChar;
- if (this.fDocumentHandler != null) {
- this.callCharDataHandler(var2, super.fCurrentOffset - var2, var1.inCDSect);
- }
-
- return 12;
- }
-
- byte var8 = XMLReader.fgCharFlags[var3];
- if ((var8 & 8) == 0) {
- if (var3 == 60) {
- ++super.fCharacterCounter;
- if (this.fDocumentHandler != null) {
- this.callCharDataHandler(var2, super.fCurrentOffset - this.fBytesPerChar - var2, var1.inCDSect);
- }
-
- return 9;
- }
-
- if (var3 == 38) {
- ++super.fCharacterCounter;
- if (this.fDocumentHandler != null) {
- this.callCharDataHandler(var2, super.fCurrentOffset - this.fBytesPerChar - var2, var1.inCDSect);
- }
-
- return 10;
- }
-
- if (var3 == 10) {
- ++super.fLinefeedCounter;
- super.fCharacterCounter = 1;
- } else if (var3 == 13) {
- ++super.fCarriageReturnCounter;
- super.fCharacterCounter = 1;
- } else {
- if (var3 != 93) {
- super.fCurrentOffset -= this.fBytesPerChar;
- if (this.fDocumentHandler != null) {
- this.callCharDataHandler(var2, super.fCurrentOffset - var2, var1.inCDSect);
- }
-
- return 12;
- }
-
- if (this.getChar(super.fCurrentOffset) == 93 && this.getChar(super.fCurrentOffset + this.fBytesPerChar) == 62) {
- if (this.fDocumentHandler != null) {
- this.callCharDataHandler(var2, super.fCurrentOffset - this.fBytesPerChar - var2, var1.inCDSect);
- }
-
- super.fCharacterCounter += 3;
- super.fCurrentOffset += 2 * this.fBytesPerChar;
- return 11;
- }
-
- ++super.fCharacterCounter;
- }
- } else {
- ++super.fCharacterCounter;
- }
- } else {
- if (var3 >= 55296 && var3 <= 57343) {
- ++super.fCharacterCounter;
- super.fCurrentOffset += this.fBytesPerChar;
- } else if (var3 == 65534 || var3 == 65535) {
- super.fCurrentOffset -= this.fBytesPerChar;
- if (this.fDocumentHandler != null) {
- this.callCharDataHandler(var2, super.fCurrentOffset - var2, var1.inCDSect);
- }
-
- return 12;
- }
-
- ++super.fCharacterCounter;
- }
-
- var3 = this.getChar(super.fCurrentOffset);
- super.fCurrentOffset += this.fBytesPerChar;
- }
- }
- }
-